/*
 * @lc app=leetcode.cn id=693 lang=cpp
 *
 * [693] 交替位二进制数
 */

// @lc code=start
class Solution
{
public:
  bool hasAlternatingBits(int n)
  {
    int mask = 0x00000003 & n;
    if (mask != 1 && mask != 2)
      return false;
    while (n != 0) {
      if ((n & 3) != mask)
        return false;
      n >>= 2;
    }
    return true;
  }
};
// @lc code=end
